package driver

import (
	"tms-server/env"

	"github.com/go-redis/redis"
)

var (
	Redis *redis.Client
)

// InitRedis 初始化redis
func InitRedis() (closeFunc func(), err error) {
	option := redis.Options{
		Addr:     env.Confs.RedisAddr,
		Password: env.Confs.RedisPassword,
		DB:       0,
	}
	Redis = redis.NewClient(&option)
	_, err = Redis.Ping().Result()
	if err != nil {
		return
	}
	closeFunc = func() {
		Redis.Close()
	}
	return
}
